home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / exfalsowindow.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  11KB  |  256 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. from gi.repository import Gtk, GObject, Pango
  6. from quodlibet import config
  7. from quodlibet import const
  8. from quodlibet import formats
  9. from quodlibet import qltk
  10. from quodlibet.plugins import PluginManager
  11. from quodlibet.qltk.delete import trash_files, TrashMenuItem
  12. from quodlibet.qltk.edittags import EditTags
  13. from quodlibet.qltk.filesel import MainFileSelector
  14. from quodlibet.qltk.pluginwin import PluginWindow
  15. from quodlibet.qltk.renamefiles import RenameFiles
  16. from quodlibet.qltk.tagsfrompath import TagsFromPath
  17. from quodlibet.qltk.tracknumbers import TrackNumbers
  18. from quodlibet.qltk.entry import UndoEntry
  19. from quodlibet.qltk.about import AboutExFalso
  20. from quodlibet.qltk.songsmenu import SongsMenuPluginHandler
  21. from quodlibet.qltk.x import Alignment, SeparatorMenuItem, ConfigRHPaned
  22. from quodlibet.qltk.window import PersistentWindowMixin, Window, UniqueWindow
  23. from quodlibet.util.path import mtime, normalize_path
  24. from quodlibet.util import connect_obj, connect_destroy
  25.  
  26. class ExFalsoWindow(Window, PersistentWindowMixin):
  27.     __gsignals__ = {
  28.         'changed': (GObject.SignalFlags.RUN_LAST, None, (object,)),
  29.         'artwork-changed': (GObject.SignalFlags.RUN_LAST, None, (object,)) }
  30.     pm = SongsMenuPluginHandler()
  31.     
  32.     def init_plugins(cls):
  33.         PluginManager.instance.register_handler(cls.pm)
  34.  
  35.     init_plugins = classmethod(init_plugins)
  36.     
  37.     def __init__(self, library, dir = None):
  38.         super(ExFalsoWindow, self).__init__(dialog = False)
  39.         self.set_title('Ex Falso')
  40.         self.set_default_size(750, 475)
  41.         self.enable_window_tracking('exfalso')
  42.         self._ExFalsoWindow__library = library
  43.         hp = ConfigRHPaned('memory', 'exfalso_paned_position', 1)
  44.         hp.set_border_width(0)
  45.         hp.set_position(250)
  46.         hp.show()
  47.         self.add(hp)
  48.         vb = Gtk.VBox()
  49.         bbox = Gtk.HBox(spacing = 6)
  50.         about = Gtk.Button()
  51.         about.add(Gtk.Image.new_from_stock(Gtk.STOCK_ABOUT, Gtk.IconSize.BUTTON))
  52.         connect_obj(about, 'clicked', self._ExFalsoWindow__show_about, self)
  53.         bbox.pack_start(about, False, True, 0)
  54.         prefs = Gtk.Button()
  55.         prefs.add(Gtk.Image.new_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.BUTTON))
  56.         
  57.         def prefs_cb(button):
  58.             window = PreferencesWindow(self)
  59.             window.show()
  60.  
  61.         prefs.connect('clicked', prefs_cb)
  62.         bbox.pack_start(prefs, False, True, 0)
  63.         plugins = qltk.Button(_('_Plugins'), Gtk.STOCK_EXECUTE)
  64.         
  65.         def plugin_window_cb(button):
  66.             window = PluginWindow(self)
  67.             window.show()
  68.  
  69.         plugins.connect('clicked', plugin_window_cb)
  70.         bbox.pack_start(plugins, False, True, 0)
  71.         l = Gtk.Label()
  72.         l.set_alignment(1, 0.5)
  73.         l.set_ellipsize(Pango.EllipsizeMode.END)
  74.         bbox.pack_start(l, True, True, 0)
  75.         fs = MainFileSelector()
  76.         vb.pack_start(fs, True, True, 0)
  77.         vb.pack_start(Alignment(bbox, border = 6), False, True, 0)
  78.         vb.show_all()
  79.         hp.pack1(vb, resize = True, shrink = False)
  80.         nb = qltk.Notebook()
  81.         nb.props.scrollable = True
  82.         nb.show()
  83.         for Page in [
  84.             EditTags,
  85.             TagsFromPath,
  86.             RenameFiles,
  87.             TrackNumbers]:
  88.             page = Page(self, self._ExFalsoWindow__library)
  89.             page.show()
  90.             nb.append_page(page)
  91.         
  92.         align = Alignment(nb, top = 3)
  93.         align.show()
  94.         hp.pack2(align, resize = True, shrink = False)
  95.         fs.connect('changed', self._ExFalsoWindow__changed, l)
  96.         if dir:
  97.             fs.go_to(dir)
  98.         connect_destroy(self._ExFalsoWindow__library, 'changed', self._ExFalsoWindow__library_changed, fs)
  99.         self._ExFalsoWindow__save = None
  100.         connect_obj(self, 'changed', self.set_pending, None)
  101.         for c in fs.get_children():
  102.             c.get_child().connect('button-press-event', self._ExFalsoWindow__pre_selection_changed, fs, nb)
  103.             c.get_child().connect('focus', self._ExFalsoWindow__pre_selection_changed, fs, nb)
  104.         
  105.         fs.get_children()[1].get_child().connect('popup-menu', self._ExFalsoWindow__popup_menu, fs)
  106.         self.emit('changed', [])
  107.         self.get_child().show()
  108.         self._ExFalsoWindow__ag = Gtk.AccelGroup()
  109.         (key, mod) = Gtk.accelerator_parse('<control>Q')
  110.         self._ExFalsoWindow__ag.connect(key, mod, (0,), (lambda : self.destroy()))
  111.         self.add_accel_group(self._ExFalsoWindow__ag)
  112.  
  113.     
  114.     def __library_changed(self, library, songs, fs):
  115.         fs.rescan()
  116.  
  117.     
  118.     def set_as_osx_window(self, osx_app):
  119.         pass
  120.  
  121.     
  122.     def __show_about(self, window):
  123.         about = AboutExFalso(self)
  124.         about.run()
  125.         about.destroy()
  126.  
  127.     
  128.     def set_pending(self, button, *excess):
  129.         self._ExFalsoWindow__save = button
  130.  
  131.     
  132.     def __pre_selection_changed(self, view, event, fs, nb):
  133.         if self._ExFalsoWindow__save:
  134.             resp = qltk.CancelRevertSave(self).run()
  135.             if resp == Gtk.ResponseType.YES:
  136.                 self._ExFalsoWindow__save.clicked()
  137.             elif resp == Gtk.ResponseType.NO:
  138.                 fs.rescan()
  139.             else:
  140.                 nb.grab_focus()
  141.                 return True
  142.  
  143.     
  144.     def __popup_menu(self, view, fs):
  145.         filenames = [ normalize_path(f, canonicalise = True) for f in fs.get_selected_paths() ]
  146.         maybe_songs = [ self._ExFalsoWindow__library.get(f) for f in filenames ]
  147.         songs = [ s for s in maybe_songs if s ]
  148.         if songs:
  149.             menu = self.pm.Menu(self._ExFalsoWindow__library, self, songs)
  150.             if menu is None:
  151.                 menu = Gtk.Menu()
  152.             else:
  153.                 menu.prepend(SeparatorMenuItem())
  154.         else:
  155.             menu = Gtk.Menu()
  156.         b = TrashMenuItem()
  157.         b.connect('activate', self._ExFalsoWindow__delete, filenames, fs)
  158.         menu.prepend(b)
  159.         connect_obj(menu, 'selection-done', Gtk.Menu.destroy, menu)
  160.         menu.show_all()
  161.         return view.popup_menu(menu, 0, Gtk.get_current_event_time())
  162.  
  163.     
  164.     def __delete(self, item, paths, fs):
  165.         trash_files(self, paths)
  166.         fs.rescan()
  167.  
  168.     
  169.     def __changed(self, selector, selection, label):
  170.         (model, rows) = selection.get_selected_rows()
  171.         files = []
  172.         if len(rows) < 2:
  173.             if not model:
  174.                 pass
  175.             count = len([])
  176.         else:
  177.             count = len(rows)
  178.         label.set_text(ngettext('%d song', '%d songs', count) % count)
  179.         for row in rows:
  180.             filename = model[row][0]
  181.             if not os.path.exists(filename):
  182.                 continue
  183.             if filename in self._ExFalsoWindow__library:
  184.                 file = self._ExFalsoWindow__library[filename]
  185.                 if file('~#mtime') + 1 < mtime(filename):
  186.                     
  187.                     try:
  188.                         file.reload()
  189.                     except StandardError:
  190.                         pass
  191.                     
  192.  
  193.                 files.append(file)
  194.                 continue
  195.             files.append(formats.MusicFile(filename))
  196.         
  197.         files = filter(None, files)
  198.         if len(files) == 0:
  199.             self.set_title('Ex Falso')
  200.         elif len(files) == 1:
  201.             self.set_title('%s - Ex Falso' % files[0].comma('title'))
  202.         else:
  203.             self.set_title('%s - Ex Falso' % ngettext('%(title)s and %(count)d more', '%(title)s and %(count)d more', len(files) - 1) % {
  204.                 'title': files[0].comma('title'),
  205.                 'count': len(files) - 1 })
  206.         self._ExFalsoWindow__library.add(files)
  207.         self.emit('changed', files)
  208.  
  209.  
  210.  
  211. class PreferencesWindow(UniqueWindow):
  212.     
  213.     def __init__(self, parent):
  214.         if self.is_not_unique():
  215.             return None
  216.         None(PreferencesWindow, self).__init__()
  217.         self.set_title(_('Ex Falso Preferences'))
  218.         self.set_border_width(12)
  219.         self.set_resizable(False)
  220.         self.set_transient_for(parent)
  221.         vbox = Gtk.VBox(spacing = 6)
  222.         hb = Gtk.HBox(spacing = 6)
  223.         e = UndoEntry()
  224.         e.set_text(config.get('editing', 'split_on'))
  225.         e.connect('changed', self._PreferencesWindow__changed, 'editing', 'split_on')
  226.         l = Gtk.Label(label = _('Split _on:'))
  227.         l.set_use_underline(True)
  228.         l.set_mnemonic_widget(e)
  229.         hb.pack_start(l, False, True, 0)
  230.         hb.pack_start(e, True, True, 0)
  231.         vbox.pack_start(hb, False, True, 0)
  232.         f = qltk.Frame(_('Tag Editing'), child = vbox)
  233.         close = Gtk.Button(stock = Gtk.STOCK_CLOSE)
  234.         connect_obj(close, 'clicked', (lambda x: x.destroy()), self)
  235.         button_box = Gtk.HButtonBox()
  236.         button_box.set_layout(Gtk.ButtonBoxStyle.END)
  237.         button_box.pack_start(close, True, True, 0)
  238.         main_vbox = Gtk.VBox(spacing = 12)
  239.         main_vbox.pack_start(f, True, True, 0)
  240.         self.use_header_bar()
  241.         if not self.has_close_button():
  242.             main_vbox.pack_start(button_box, False, True, 0)
  243.         self.add(main_vbox)
  244.         connect_obj(self, 'destroy', PreferencesWindow._PreferencesWindow__destroy, self)
  245.         self.get_child().show_all()
  246.  
  247.     
  248.     def __changed(self, entry, section, name):
  249.         config.set(section, name, entry.get_text())
  250.  
  251.     
  252.     def __destroy(self):
  253.         config.write(const.CONFIG)
  254.  
  255.  
  256.